<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>修改商品页面</h1>
 <div>
     <!--readonly设置只读-->
     <input type="text" v-model="product.id" placeholder="id" readonly>
     <input type="text" v-model="product.title" placeholder="标题" >
     <input type="text" v-model="product.price" placeholder="价格" >
     <input type="text" v-model="product.saleCount" placeholder="销量" >
     <input type="button" value="修改" @click="update()">
 </div>
<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"div",
        data:{
                product:{}
        },
        created:function () {
            /*location.search获取参数的?和参数?id=4
            * location.search.spilt("=")[1]
            * */
            //通过地址栏获得id
            let id = location.search.split("=")[1];
            //发出异步请求
            axios.get("/selectById?id="+id).then(function (response) {
                //把服务查询回来的商品信息复制给vue里面的product变量
                //让页面和product对象进行绑定 当product得到值页面就会显示出来
                v.product = response.data;

            })
        },methods:{
            update(){
               //发出异步请求
                axios.post("/update",v.product).then(function (response) {
                    alert("修改完成");
                    location.href="/list.html";
                })
            }
        }
    })
</script>
</body>
</html>